[Unit]
Description=kubelet: The Kubernetes Node Agent
Documentation=https://kubernetes.io/docs/home/
Wants=network-online.target
{% if KUBE_RUNTIME == "containerd" %}
After=containerd.service
Requires=containerd.service
{% elif KUBE_RUNTIME == "crio"  %}
After=crio.service
Requires=crio.service
{% else %}
After=docker.service
Requires=docker.service
{% endif %}

[Service]
Slice=podruntime.slice
ExecStart=/usr/local/bin/kubelet \
  --kubeconfig=/etc/kubernetes/kubelet.kubeconfig \
  --config=/var/lib/kubelet/config.yaml \
  --pod-infra-container-image={{ REGISTRY_URL | default('https://registry.aliyuncs.com') | urlsplit('hostname') }}{% if REGISTRY_URL | default('https://registry.aliyuncs.com') | urlsplit('port') is not none %}:{{REGISTRY_URL | default('https://registry.aliyuncs.com') | urlsplit('port')}}{% endif %}{% if REGISTRY_URL | default('https://registry.aliyuncs.com') | urlsplit('path') is not none %}{{ REGISTRY_URL | default('https://registry.aliyuncs.com') | urlsplit('path') }}{% endif %}/google_containers/pause:{{ KUBE_VERSION | component_version | community.general.json_query("plugin.pause") }} \
{% if ipv6 is defined %}
  --node-ip={{ inventory_hostname }},{{ ipv6 }} \
{% else %}
  --node-ip={{ inventory_hostname }} \
{% endif %}
{% if nodename is defined %}
  --hostname-override={{ nodename | lower }} \
{% else %}
  --hostname-override={{ ansible_hostname | lower }} \
{% endif %}
{% if KUBE_RUNTIME == "containerd" %}
  --runtime-request-timeout=15m \
  --container-runtime-endpoint=unix:///run/containerd/containerd.sock \
{% endif %}
{% if KUBE_RUNTIME == "crio" %}
  --runtime-request-timeout=15m \
  --container-runtime-endpoint=unix:///var/run/crio/crio.sock \
{% endif %}
{% if kubelet.extraArgs is defined %}
{% for extraArg in kubelet.extraArgs %}
  {{ extraArg }} \
{% endfor %}
{% endif %}
{% if KUBE_VERSION is version("1.19",">") %}
  --logging-format=json \
{% endif %}
  --v={{ kubelet.log.level | default(1) }}

Restart=on-failure
StartLimitInterval=0
RestartSec=10

[Install]
WantedBy=multi-user.target
